﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;
using Maticsoft.Common;
using LTP.Accounts.Bus;
namespace lcs.Web.storeinfo
{
    public partial class Add : Page
    {
        lcs.BLL.user bu = new BLL.user();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                lcs.BLL.stype bs = new BLL.stype();
                ddltype.DataSource = bs.GetAllList().Tables[0];
                ddltype.DataTextField = "stname";
                ddltype.DataValueField = "stid";
                ddltype.DataBind();
                DataSet ds = bu.GetUserRoles(" roles_name='仓管员'");
                ddluser.DataSource = ds.Tables[0];
                ddluser.DataTextField = "user_name";
                ddluser.DataValueField = "user_id";
                ddluser.DataBind();            

            }

        }

        protected void btnSave_Click(object sender, EventArgs e)
        {

            string strErr = "";
            if (this.txtsname.Text.Trim().Length == 0)
            {
                strErr += "仓库名称不能为空！\\n";
            }
            if (this.txtsadd.Text.Trim().Length == 0)
            {
                strErr += "仓库地址不能为空！\\n";
            }            
            if (strErr != "")
            {
                MessageBox.Show(this, strErr);
                return;
            }
            string sname = this.txtsname.Text;
            string sadd = this.txtsadd.Text;
            int stype = int.Parse(this.ddltype.SelectedValue);
            string sdes = this.txtsdes.Text;
            string sremark = this.txtsremark.Text;
            int uid = int.Parse(ddluser.SelectedValue.ToString());
            lcs.Model.storeinfo model = new lcs.Model.storeinfo();
            model.sname = sname;
            model.sadd = sadd;
            model.stype = stype;
            model.sdes = sdes;
            model.sremark = sremark;
            model.uid = uid;
            lcs.BLL.storeinfo bll = new lcs.BLL.storeinfo();
            bll.Add(model);
            Maticsoft.Common.MessageBox.ShowAndRedirect(this, "保存成功！", "List.aspx");

        }


        public void btnCancle_Click(object sender, EventArgs e)
        {
            Response.Redirect("List.aspx");
        }
    }
}
